# From Greblus: http://blog.greblus.net/2014/11/18/msys2mingw-w64-cython-i-ipython-notebook/

_realname=zeromq
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.1.4
pkgrel=1
pkgdesc="Fast messaging system built on sockets, C and C++ bindings. aka 0MQ, ZMQ (mingw-w64)"
arch=('any')
url="http://www.zeromq.org"
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-libsodium")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' '!strip' '!buildflags')
source=("http://download.zeromq.org/${_realname}-${pkgver}.tar.gz"
        winxp-compatibility.patch
        includes-consistent.patch
        mingw-w64-cmake.patch)
sha256sums=('e99f44fde25c2e4cb84ce440f87ca7d3fe3271c2b8cfbc67d55e4de25e6fe378'
            '1c8f0ff16474dfdcf721769e23d91789d9faceac59fd12eb252a7c2d7bf00200'
            '4cda5346087bd9f9d2f15249741e7b4593e2b2617177a1ba5a623f3e39485127'
            'dd7360847b9e15d44ba0d6b96ee3bafaa96d0823c8c3240edbff6ab869481621')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/winxp-compatibility.patch
  patch -p1 -i ${srcdir}/includes-consistent.patch
  patch -p1 -i ${srcdir}/mingw-w64-cmake.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p ${srcdir}/build-${CARCH}
  cd ${srcdir}/build-${CARCH}
  
  # CXXFLAGS+=" -DZMQ_HAVE_WINDOWS_TARGET_XP" - for next version
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --with-libsodium

  make
}

package() {
  mkdir -p "${pkgdir}${MINGW_PREFIX}/bin"

  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="${pkgdir}" install
}
